using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;


public class StarNode
{
 #region Members

    public Vector3 Position = new Vector3();
    public float TotalScore = 0;
    StarNode Parent = null;
    public List<StarNode> Adyacentes = new List<StarNode>();
    public bool Open = false;
    public bool Closed = false;

    /*public int row;
    public int col;
    public int floor;*/

#endregion



    public StarNode(Vector3 position)
    {
        this.Position = position;
    }
    /// <summary>
    /// Pide asignar un nuevo padre al nodo, se asigna si este no tiene padre o
    /// si el nuevo padre tiene menor score.
    /// </summary>
    /// <param name="NewParent"></param>
    /// <returns>Devuelve si se asigno un nuevo padre o no</returns>
    public bool SetParent(StarNode NewParent)
    {
        if (Parent == null || NewParent.TotalScore <= Parent.TotalScore)
        {
            AssignParent(NewParent);
            return true;
        }
        else
        {
            return false;
        }

    }
    /// <summary>
    /// Le asigna un padre y le da el score del padre + lo que cuesta moverse hasta este nodo.
    /// </summary>
    /// <param name="parent"></param>
    private void AssignParent(StarNode parent)
    {
        Parent = parent;
        TotalScore = parent.TotalScore + Vector3.Distance(parent.Position, this.Position);
    }
    public StarNode GetParent()
    {
        return Parent;
    }
    /// <summary>
    /// devuelve el score mas la heuristica (no sabia que nombre ponerle a la funcion)
    /// </summary>
    /// <param name="destiny"></param>
    public float GetSH(StarNode destiny)
    {
        return TotalScore + Vector3.Distance(this.Position, destiny.Position);
    }
    public void Reset()
    {
        Open = false;
        Closed = false;
        Parent = null;
        TotalScore = 0;
    }
    public void AddAdyacent(StarNode node)
    {
        if (node != null)
        {
            Adyacentes.Add(node);
        }
    }
}

